import { h } from 'vue'
import request from '@/utils/request'
const url = 'http://10.2.1.130:8130/steel_pmo/project'
export default class Project {
    constructor() {

    }
    pageObj(data: any) {
        return request.post({
            url: `${url}/pageObj`,

            data
        })
    }
    count4Page(data: any) {
        return request.post({
            url: `${url}/count4Page`,

            data
        })
    }
    createObj(data: any): any {
        return request.post({
            url: `${url}/createObj`,

            data: this.format(data)
        })
    }
    getObjById(data: any): any {
        return request.post({
            url: `${url}/getObjById`,

            data
        })
    }

    updateObj(data: any): any {
        return request.post({
            url: `${url}/updateObj`,

            data: this.format(data)
        })
    }

    listObj(data: any): any {
        return request.post({
            url: `${url}/listObj`,

            data
        })
    }

    deleteObj(data: any): any {
        const ID = this.getKey(data)
        return request.post({
            url: `${url}/deleteObj`,

            data: { ID }
        })
    }
    downloadTestScript(targetId: string): any {
        return request.post({
            url: `${url}/downloadTestScript`,
            data: {
                Id: targetId
            }
        });
    }
    deleteObjs(data: any): any {
        return request.post({
            url: `${url}/deleteObjs`,

            data
        })
    }
    calculateIncoming(data: any): any {
        return request.post({
            url: `${url}/calculateIncoming`,

            data
        })
    }

    getDesc(obj: any): any {
        return obj.Name
    }
    getKey(obj: any): any {
        return "" + obj.Token
    }
    getDescField(): any {
        return 'Name'
    }
    getKeyField(obj: any): any {
        return ["Token"]
    }
    format(obj: any): any {
        if (null !== obj.BehaveProgress && undefined !== obj.BehaveProgress) {
            obj.BehaveProgress = parseFloat("" + obj.BehaveProgress)
        }
        if (null !== obj.CalculateUtc && undefined !== obj.CalculateUtc) {
            obj.CalculateUtc = parseFloat("" + obj.CalculateUtc)
        }
        if (null !== obj.CurrentIncome && undefined !== obj.CurrentIncome) {
            obj.CurrentIncome = parseFloat("" + obj.CurrentIncome)
        }
        if (null !== obj.IncomePerTon && undefined !== obj.IncomePerTon) {
            obj.IncomePerTon = parseFloat("" + obj.IncomePerTon)
        }
        if (null !== obj.TargetIncome && undefined !== obj.TargetIncome) {
            obj.TargetIncome = parseFloat("" + obj.TargetIncome)
        }
        if (null !== obj.IncomePerTon && undefined !== obj.IncomePerTon) {
            obj.IncomePerTon = parseFloat("" + obj.IncomePerTon)
        }
        return obj
    }
    format4Select(obj: any): any {
        return obj
    }
    // 字段的名称
    fields = [
        {
            title: '项目编号',
            dataIndex: 'Token',
            key: 'project.token',
            query: true,
            sorter: true,
            hide: false,
            editor: true,
            width: 112
        },
        {
            title: '公司',
            dataIndex: 'CompanyDesp',
            key: 'company0.name',
            query: true,
            sorter: true,
            editor: true
        },
        {
            title: '工序',
            dataIndex: 'ProcessDesp',
            key: 'process0.name',
            query: true,
            sorter: true,
            editor: true,
            width: 100
        },
        {
            title: '名称',
            dataIndex: 'Name',
            key: 'project.name',
            query: true,
            sorter: true,
            editor: true
        },

        {
            title: '部门',
            dataIndex: 'DepartmentDesp',
            key: 'department0.name',
            query: false,
            sorter: true
        },

        {
            title: '计算时间',
            dataIndex: 'CalculateUtc',
            key: 'project.calculate_utc',
            query: false,
            sorter: true,
            hide: true,
            editor: true
        },
        {
            title: '吨钢效益',
            dataIndex: 'IncomePerTon',
            key: 'project.income_per_ton',
            query: false,
            sorter: true,
            hide: true,
            editor: true,
        },
        {
            title: '效益描述',
            dataIndex: 'IncomeDescription',
            key: 'project.income_description',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '当前收益',
            dataIndex: 'CurrentIncome',
            key: 'project.current_income',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '目标收益',
            dataIndex: 'TargetIncome',
            key: 'project.target_income',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '举措进度',
            dataIndex: 'BehaveProgress',
            key: 'project.behave_progress',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '负责人',
            dataIndex: 'Responsible',
            key: 'project.responsible',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '检查人',
            dataIndex: 'Inspected',
            key: 'project.Inspected',
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '检查状态',
            dataIndex: 'InspectedStatus',
            key: 'project.InspectedStatus',
            render: (t: any, itemData: any, item: any) => {
                switch (itemData) {
                    case "0": return h('span', {}, '通过')
                    case "1": return h('span', {}, '未通过')
                    case "2": return h('span', {}, '未检查')
                }
            },
            query: false,
            sorter: true,
            hide: true
        },
        {
            title: '错误信息',
            dataIndex: 'ErrorTxt',
            key: 'project.error_txt',
            query: false,
            sorter: true,
            hide: true,
            editor: true
        },
        {
            title: '代码',
            dataIndex: 'Script',
            key: 'project.script',
            query: false,
            sorter: true,
            hide: true,
            editor: true,
            render: (t: any, itemData: any, item: any) => {
                if (itemData == null || itemData === "")
                    return h('span', {}, '无')
                else
                    return h('span', {}, '有')
            }
        }
    ]
}
